FROM python:3.10-alpine

# 设置工作目录和环境变量
WORKDIR /app
ENV PYTHONPATH=/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# 配置镜像源为国内镜像源
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main" > /etc/apk/repositories && \
    echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community" >> /etc/apk/repositories

# 安装系统依赖
RUN apk add --no-cache \
    gcc \
    musl-dev \
    postgresql-dev \
    netcat-openbsd \
    curl \
    postgresql-client && \
    rm -rf /var/cache/apk/*

# 复制并安装Python依赖
# 先复制requirements.txt，利用Docker缓存层优化构建
COPY vul_project/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip install debugpy -i https://pypi.tuna.tsinghua.edu.cn/simple

# 直接复制整个vul_project目录到工作目录
COPY vul_project/ .

# 复制启动脚本并设置执行权限
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

# 暴露端口
EXPOSE 8000 5678

# 设置启动命令
CMD ["/app/start.sh"]